const
	crypto = require('crypto');

module.exports = class extends nirvana.Controller {
	constructor(options){
		super(options);
	}
	encrypt(algorithm, content){
		let hash = crypto.createHash(algorithm);
		return hash.update(content).digest('hex');
	}
	/**
	 * MD4
	 * @param {string} text
	 */
	md4Action(param){
		return this.encrypt('md4', param.text);
	}
	/**
	 * MD5
	 * @param {string} text 明文
	 * @usage /hash/md5?text=123456
	 */
	md5Action(param){
		return this.encrypt('md5', param.text);
	}
	/**
	 * SHA1
	 * @param {string} text 明文
	 * @usage /hash/sha1?text=123456
	 */
	sha1Action(param){
		return this.encrypt('sha1', param.text);
	}
	/**
	 * SHA224
	 * @param {string} text 明文
	 * @usage /hash/sha224?text=123456
	 */
	sha224Action(param){
		return this.encrypt('sha224', param.text);
	}
	/**
	 * SHA256
	 * @param {string} text 明文
	 * @usage /hash/sha256?text=123456
	 */
	sha256Action(param){
		return this.encrypt('sha256', param.text);
	}
	/**
	 * SHA384
	 * @param {string} text
	 */
	sha384Action(param){
		return this.encrypt('sha384', param.text);
	}
	/**
	 * SHA512
	 * @param {string} text 明文
	 * @usage /hash/sha512?text=123456
	 */
	sha512Action(param){
		return this.encrypt('sha512', param.text);
	}
	/**
	 * MDC2
	 * @param {string} text
	 */
	mdc2Action(param){
		return this.encrypt('mdc2', param.text);
	}
	/**
	 * RMD60,RIPEMD160
	 * @param {string} text
	 */
	rmd160Action(param){
		return this.encrypt('rmd160', param.text);
	}
	/**
	 * WHIRLPOOL
	 * @param {string} text
	 */
	whirlpoolAction(param){
		return this.encrypt('whirlpool', param.text);
	}
}